package com.atguigu.a_collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Demo4 {
    public static void main(String[] args) {
        //创建集合对象
        Collection<String> col = new ArrayList<>();
        System.out.println("col = " + col);//[]

        //添加元素
        col.add("张三");
        col.add("李四");
        col.add("王五");
        System.out.println("col = " + col);//["张三","李四","王五"]

        //1. 获取迭代器对象
        Iterator<String> iterator = col.iterator(); //多态 Iterator<String> iterator = new Itr();

        //2. 循环遍历集合
        while(iterator.hasNext()){
            //进入循环说明有下一个元素 -> 3. 获取下一个元素
            String name = iterator.next();
            System.out.println("name = " + name);
        }

        System.out.println("--------------------------");
        //增强for
        for (String name : col) {

        }
    }
}
